package com.cqs.leetcode.tree;

import com.cqs.leetcode.TreeNode;

/**
 * @author lixqw
 * @date 2020/9/24
 */
public class BinarySearchTreeGreaterSumTree1038 {

    int sum = 0;
    public TreeNode bstToGst(TreeNode root) {
        inorder(root);
        return root;
    }

    private void inorder(TreeNode root){
        if (root == null) return;
        inorder(root.right);
        sum += root.val;
        root.val = sum;
        inorder(root.left);
    }
}

